<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String editType=request.getParameter("editType");
pageContext.setAttribute("editType",editType);
%>
<!--  添加选项值 2010-07-04 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

	<title>添加选项值</title>
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script src="dwr/engine.js"></script>
	<script src="dwr/util.js"></script>
	<script src="dwr/interface/shiyueDwr.js"></script>
	<script src="<%=path%>/js/validate.js" type="text/javascript"></script>
	<script type="text/javascript">
      
      function doSubmitForm(){
      		var codevalue=document.getElementById('codeValue').value;
      		var codeName=document.getElementById('codeName').value;
      		var valueId=document.getElementById('valueId').value;
      		var sort=document.getElementById('sort').value;
      		if(codevalue=="")
      		{
      			alert("值不能为空！");
      			return;
      		}
      		else if(codeName=="")
      		{
      			alert("选项不能为空！");
      			return;
      		}
      		else if(sort=="")
      		{
      			alert("序号不能为空");
      			return;
      		}
      		else if(valueId=="")
      		{
			    syAjax.request("post","<%=path %>/updateCodeSelectCodeMaintenanceAction.action","codeSelect.codeMaintenanceType.codeId=${codeId}&codeSelect.value="+codevalue+"&codeSelect.name="+codeName+"&codeSelect.sort="+sort,{success:initSuccessResult,fail:onFail,type:'plain'});
			}
			else
			{
				syAjax.request("post","<%=path %>/updateCodeSelectCodeMaintenanceAction.action","codeSelect.codeMaintenanceType.codeId=${codeId}&codeSelect.value="+codevalue+"&codeSelect.name="+codeName+"&codeSelect.valueId="+valueId+"&codeSelect.sort="+sort,{success:initSuccessResult,fail:onFail,type:'plain'});
			}
		}
		function initSuccessResult(response){
			if(response=="true"){
				window.returnValue='true';
				window.close();
			}
		}
		
		var a=true;
		//判断选项值是否唯一(dwr)
		function checkValue()
		{
		   var valueId=document.getElementById('valueId').value;
		   //判断是增加或者是修改---增加
		   if(valueId=="")
		   {
		   var codeValue=document.getElementById("codeValue").value;
		   shiyueDwr.isCodeSelectValueExsit('${codeId}',codeValue, 
		   function(isVal)
		   {
			   if(isVal==false && a==true)
			   {
			     alert("该选项值已经存在！");
			     document.getElementById("codeValue").value="";
			     document.getElementById("codeValue").focus();
			   }
			
		   }
		   );
		   }
		   else
		   {
		   		var codeValue=document.getElementById("codeValue").value;
		   		if(codeValue=='${requestScope.codeSelect.value}')
		   		{
		   		
		   		}
		   		else
		   		{
		   			shiyueDwr.isCodeSelectValueExsit('${codeId}',codeValue, 
				   function(isVal)
				   {
					   if(isVal==false && a==true)
					   {
					     alert("该选项值已经存在！");
					     document.getElementById("codeValue").value="";
					     document.getElementById("codeValue").focus();
					   }
					
				   }
				   );
		   		}
		   }
		}
		
		//判断序号是否唯一(dwr)
		function checkSort()
		{
		   var valueId=document.getElementById('valueId').value;
		   //判断是增加或者是修改---增加
		   if(valueId=="")
		   {
		   var sort=document.getElementById("sort").value;
		   shiyueDwr.isCodeSelectSortExsit('${codeId}',sort, 
		   function(isVal)
		   {
			   if(isVal==false && a==true)
			   {
			     alert("序号不能添加重复！");
			     document.getElementById("sort").focus();
			   }
			
		   }
		   );
		   }
		   else
		   {
		   	  var sort=document.getElementById("sort").value;
		   	  if(sort=='${requestScope.codeSelect.sort}')
		   	  {
		   	  	
		   	  }	
		   	  else
		   	  {
		   	  	shiyueDwr.isCodeSelectSortExsit('${codeId}',sort, 
			   function(isVal)
			   {
				   if(isVal==false && a==true)
				   {
				     alert("序号不能添加重复！");
				     document.getElementById("sort").focus();
				   }
				
			   }
			   );
		   	  }
		   }
		}
		
		function window.onbeforeunload()
		{
		  a=false;
		}
	</script>

  </head>
  
  <body bgcolor="#ECE9D8">
   <form action="" method="post">
    <c:if test="${pageScope.editType =='update'}">
    <input type="hidden" id="valueId" name="codeSelect.valueId" value="${codeSelect.valueId}" />
    </c:if>
    <input type="hidden" id="valueId" name="codeSelect.valueId" value="" />
    <input type="hidden" name="codeSelect.codeMaintenanceType.codeId" value="${codeId}" />
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="30%" bgcolor="#ECE9D8">&nbsp;</td>
    <td width="70%" align="left" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
      <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">值：</td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<c:if test="${! empty requestScope.codeSelect.value}">
    		<input id="codeValue" onblur="checkValue();" type="text" name="codeSelect.value" value="${requestScope.codeSelect.value }" readonly="readonly"/>
    	</c:if>
    	<c:if test="${empty requestScope.codeSelect.value}">
    		<input id="codeValue" onblur="checkValue();" type="text" name="codeSelect.value" value="${requestScope.codeSelect.value }" onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
    	</c:if>&nbsp;<font color="red" style="font-size: 12px;">只能是数字</font>
    </td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8"><span class="f_6">选项：</span></td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<input type="text" id="codeName" name="codeSelect.name" value="${requestScope.codeSelect.name }" />
    </td>
  </tr>
   <tr>
    <td height="30" align="right" bgcolor="#ECE9D8"><span class="f_6">序号：</span></td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<c:if test="${! empty requestScope.codeSelect.sort}">
    	<input type="text" id="sort" name="codeSelect.sort" value="${requestScope.codeSelect.sort }" onblur="checkSort();" onkeypress= "if   (event.keyCode   <   46||event.keyCode   >   57)   event.returnValue   =   false; "/>
    	</c:if>
    	<c:if test="${empty requestScope.codeSelect.sort}">
    	<input type="text" id="sort" name="codeSelect.sort" value="0" onblur="checkSort();" onkeypress= "if   (event.keyCode   <   46||event.keyCode   >   57)   event.returnValue   =   false; "/>
    	</c:if>
    </td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8"></td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<font color="red" style="font-size: 12px;">注：选项值添加后无法修改</font>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
      <tr>
    <td height="40" align="center" bgcolor="#ECE9D8"><label>
      <input type="button" name="Submit" value="提 交" onclick="javascript:doSubmitForm();"/>
    </label></td>
  </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#ECE9D8">&nbsp;</td>
    <td height="40" align="center" bgcolor="#ECE9D8"></td>
  </tr>
</table>
</form>
  </body>
</html>
